package xrz.com.jr.utils;

import org.xutils.x;
import org.xutils.image.ImageOptions;

import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;

import xrz.com.jr.BaseApp;

public class ImageUtils {

	public static void loadimg(ImageView imageView, ImageOptions imageOptions, String url,
			final OnImageLoadListener listener) {
		BaseApp.imageLoader.displayImage(url, imageView, BaseApp.options, new ImageLoadingListener() {
			
			@Override
			public void onLoadingStarted(String arg0, View arg1) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
				// TODO Auto-generated method stub
				if (listener != null)
					listener.onLoadSuccess(new BitmapDrawable(arg2));
			}
			
			@Override
			public void onLoadingCancelled(String arg0, View arg1) {
				// TODO Auto-generated method stub
				
			}
		});
//		x.image().bind(imageView, url, imageOptions, new CommonCallback<Drawable>() {
//
//			@Override
//			public void onSuccess(Drawable arg0) {
//				if (listener != null)
//					listener.onLoadSuccess(arg0);
//			}
//
//			@Override
//			public void onFinished() {
//				// TODO Auto-generated method stub
//
//			}
//
//			@Override
//			public void onError(Throwable arg0, boolean arg1) {
//				// TODO Auto-generated method stub
//
//			}
//
//			@Override
//			public void onCancelled(CancelledException arg0) {
//				// TODO Auto-generated method stub
//
//			}
//		});
	}

	/**
	 * ����ͼƬ
	 * 
	 * @param imageView
	 * @param url
	 * @param listener
	 */
	public static void loadimg(ImageView imageView, String url, final OnImageLoadListener listener) {
		loadimg(imageView, BaseApp.imageOptions, url, listener);
	}

	public static void loadimg(ImageView imageView, String url) {
		loadimg(imageView, url, null);
	}

	public interface OnImageLoadListener {
		public void onLoadSuccess(Drawable drawable);
	}

	public interface OnImageLoadByListener {
		public void onLoadSuccess(Bitmap bitmap);
	}
	
	public static void loadimgFromSDcard(ImageView imageView, String url){
		x.image().bind(imageView, url);
	}
}
